//
//  ZYCProfileParentApplyCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/21.
//

#import "ZYCProfileParentApplyCell.h"


@interface ZYCProfileParentApplyCell ()

@property (nonatomic, strong) UIImageView *courseIconView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *courseStatusLabel;
// 课程类型
@property (nonatomic, strong) UILabel *genreLabel;
// 所属课程
@property (nonatomic, strong) UILabel *sortLabel;
// 授课老师
@property (nonatomic, strong) UILabel *teacherLabel;
// 报名人数
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *applyStatusPlaceLabel;
@property (nonatomic, strong) UILabel *applyStatusLabel;

@property (nonatomic, strong) UIButton *cancelApplyButton;
@end
@implementation ZYCProfileParentApplyCell

- (void)setModel:(ZYCProfileParentApplyModel *)model{
    NSURL *url  = [NSURL URLWithString:[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.courseImg]];
    [_courseIconView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"bjc"]];
    _titleLabel.text = model.className;
    //报名状态（1-未开始，2-进行中，3-已结束）
    NSInteger enrollStatus = [model.enrollStatus integerValue];
    if (enrollStatus == 1) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#EB9F28");

    }else if (enrollStatus == 2) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#39A85B");
        
    }else if (enrollStatus == 3) {
        _courseStatusLabel.backgroundColor = HEX_RGB(@"#B9B9B9");
    }
    _genreLabel.text = [NSString stringWithFormat:@"课程类型: %@",model.courseTypeName];
    _sortLabel.text = [NSString stringWithFormat:@"所属课程: %@",model.courseName];
    _teacherLabel.text = [NSString stringWithFormat:@"授课老师: %@",model.teacherName];
    _courseStatusLabel.text = model.enrollStatusStr;
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.courseIconView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.courseStatusLabel];
        [self.contentView addSubview:self.courseIconView];
        [self.contentView addSubview:self.genreLabel];
        [self.contentView addSubview:self.sortLabel];
        [self.contentView addSubview:self.teacherLabel];
        [self.contentView addSubview:self.line];
        [self.contentView addSubview:self.applyStatusLabel];
        [self.contentView addSubview:self.applyStatusPlaceLabel];
        [self.contentView addSubview:self.cancelApplyButton];
        
        [self.courseIconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.top.equalTo(self.contentView).offset(10.0f);
            make.size.mas_equalTo(CGSizeMake(274/2, 189/2));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.courseIconView.mas_right).offset(10.0f);
            make.right.equalTo(self.courseStatusLabel.mas_left).offset(-5.0f);
            make.top.equalTo(self.courseIconView);
        }];
        
        [self.courseStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-25.0f);
            make.centerY.equalTo(self.titleLabel);
            make.size.mas_equalTo(CGSizeMake(56.0f, 23.0f));
        }];
        
        [self.genreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(15.0f);
            make.left.equalTo(self.titleLabel);
        }];
        [self.sortLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.genreLabel.mas_bottom).offset(9.0f);
            make.left.equalTo(self.titleLabel);
        }];
        [self.teacherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.sortLabel.mas_bottom).offset(9.0f);
            make.left.equalTo(self.titleLabel);
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.top.equalTo(self.courseIconView.mas_bottom).offset(12.5f);
            make.height.mas_equalTo(1.0f);
        }];
        
        [self.applyStatusPlaceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.top.equalTo(self.line.mas_bottom).offset(14.0f);
        }];
        
        [self.applyStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.applyStatusPlaceLabel.mas_right).offset(10.0f);
            make.centerY.equalTo(self.applyStatusPlaceLabel);
        }];
        
        [self.cancelApplyButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.centerY.equalTo(self.applyStatusPlaceLabel);
        }];
    }
    return self;
}

- (UIImageView *)courseIconView {
    if (!_courseIconView) {
        _courseIconView = [[UIImageView alloc] init];
        _courseIconView.layer.cornerRadius = 5.0f;
        _courseIconView.layer.masksToBounds = YES;
        _courseIconView.backgroundColor = [UIColor grayColor];
    }
    return _courseIconView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(15.0f) titleColor:HEX_RGB(@"#000000") textAlignment:ZZTextAlignmentLeft];
        _titleLabel.numberOfLines = 1;
    }
    return _titleLabel;
}

- (UILabel *)courseStatusLabel {
    if (!_courseStatusLabel) {
        _courseStatusLabel = [[UILabel alloc] init];
        _courseStatusLabel.textColor = HEX_RGB(kTitleWhiteColor);
        _courseStatusLabel.font = kCustomFont(@"PingFangSC-Light", 12.0f);
        _courseStatusLabel.layer.cornerRadius = 11.5;
        _courseStatusLabel.layer.masksToBounds = YES;
        _courseStatusLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _courseStatusLabel;
}

- (UILabel *)genreLabel {
    if (!_genreLabel) {
        _genreLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _genreLabel;
}

- (UILabel *)sortLabel {
    if (!_sortLabel) {
        _sortLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _sortLabel;
}

- (UILabel *)teacherLabel {
    if (!_teacherLabel) {
        _teacherLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _teacherLabel;
}

- (UILabel *)applyStatusPlaceLabel {
    if (!_applyStatusPlaceLabel) {
        _applyStatusPlaceLabel = [UILabel LabelWithString: @"报名状态:" Font:kCustomFont(@"PingFangSC-Light", 15.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _applyStatusPlaceLabel;
}

- (UILabel *)applyStatusLabel {
    if (!_applyStatusLabel) {
        _applyStatusLabel = [UILabel LabelWithString:@"已报名" Font:kCustomFont(@"PingFangSC-Light", 15.0f) titleColor:HEX_RGB(@"#EB9F28") textAlignment:ZZTextAlignmentLeft];
    }
    return _applyStatusLabel;
}


- (UIButton *)cancelApplyButton {
    if (!_cancelApplyButton) {
        _cancelApplyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancelApplyButton setTitle:@"取消报名" forState:UIControlStateNormal];
        _cancelApplyButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 15.0f);
        [_cancelApplyButton setTitleColor:HEX_RGB(@"#2384D8") forState:UIControlStateNormal];
        [_cancelApplyButton addTarget:self action:@selector(clickCancelApplyAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelApplyButton;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#E4E4E4");
    }
    return _line;
}

- (void)clickCancelApplyAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(profileParentApplyCellDidCancelApplyWithModel:)]) {
        [self.delegate profileParentApplyCellDidCancelApplyWithModel:self.model];
    }

}
@end
